import {useEffect, useState} from "react";
import qs from "qs"
let openid_bk = localStorage.getItem("openid")
export default function useOpenid(){
    const [openid , setOpenId] = useState(openid_bk)
    useEffect(()=>{
        const code = qs.parse(location.search)?.["?code"] || qs.parse(location.search)?.["code"] || "";
        if (!openid_bk && code){
            ax.get("/gzh/getOpenid?js_code="+code).then(res=>{
                openid_bk=res.data;
                setOpenId(res.data)
            })
        }
    },[])
    return {openid}
}